package lol.clann.minecraft.springboot.api.bukkit.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author pyz
 * @date 2019/5/3 3:10 PM
 */

public interface NBTUtils {
    /**
     * 序列化NBTTagCompoun到流
     *
     * @param nbtTagCompound
     * @param out
     * @param <T>
     * @throws IOException
     */
    public <T> void serialize(T nbtTagCompound, OutputStream out) throws IOException;

    /**
     * 序列化NBTTagCompoun成二进制
     *
     * @param nbtTagCompound
     * @param <T>
     * @return
     * @throws IOException
     */
    public <T> byte[] serialize(T nbtTagCompound) throws IOException;

    /**
     * 反序列化NBTTagCompoun
     * @param in
     * @param <T>
     * @return
     * @throws IOException
     */
    public <T> T deserialize(InputStream in) throws IOException;

    /**
     * 反序列化NBTTagCompoun
     * @param bytes
     * @param <T>
     * @return
     * @throws IOException
     */
    public <T> T deserialize(byte[] bytes) throws IOException;

    /**
     * 用普通值创建NBT对象
     * @param value
     * @param <T>
     * @return
     */
    public <T> T fromValue(Object value);

    public <T> T newNBTTagList();

    /**
     * 设置NBTTagList的类型
     * @param tagList
     * @param type
     * @param <T>
     */
    public <T> void setNBTTagListType(T tagList, byte type);

    /**
     * 创建NBTTagString
     *
     * @param str
     * @param <T>
     * @return
     */
    public <T> T createNBTTagString(String str);

    public <T> T newNBTTagCompound();

    /**
     * 获取NBT包装的值
     * @param nbtTag
     * @param <T>
     * @return
     */
    public <T> T getValue(Object nbtTag);

    /**
     * 设置NBT的值
     *
     * @param nbtTag
     * @param value
     * @param <T>
     */
    public <T> void setValue(T nbtTag, Object value);

    /**
     * 获取指定key对应的NBT的值
     * @param nbtTagCompound
     * @param key
     * @param <T>
     * @return
     */
    public <T> T getValue(Object nbtTagCompound, String key);

    /**
     * 直接设置值
     *
     * @param nbtTagCompound
     * @param key
     * @param value 可以是值,也可以是nbt
     */
    public <T> void setValue(T nbtTagCompound, String key, Object value);

    /**
     * 获取指定key的NBT
     *
     * @param nbtTagCompound
     * @param key
     * @param <T>
     * @return
     */
    public <T> T get(Object nbtTagCompound, String key);

    /**
     * 获取指定key的NBTTagCompound
     * 若不存在,就创建
     *
     * @param nbtTagCompound
     * @param key
     * @param <T>
     * @return
     */
    public <T> T getOrCreateNBTTagCompound(Object nbtTagCompound, String key);
    /**
     * 获取指定key的NBTTagList
     * 若不存在,就创建
     *
     * @param nbtTagCompound
     * @param key
     * @param <T>
     * @return
     */
    public <T> T getOrCreateNBTTagList(Object nbtTagCompound, String key);

    /**
     * 设置
     *
     * @param nbtTagCompound
     * @param key
     * @param nbtTag
     * @param <T>
     */
    public <T> void set(T nbtTagCompound, String key, Object nbtTag);

    /**
     * 移除
     *
     * @param nbtTagCompound
     * @param key
     * @param <T>
     * @return
     */
    public <T> T remove(T nbtTagCompound, String key);

    public <T> int size(T nbtTag);

    /**
     * 拷贝nbt对象
     * @param nbtTag
     * @param <T>
     * @return
     */
    public <T> T deepCopy(T nbtTag);

    /**
     * 将nbt转化成rawMessage需要的josn字串
     *
     * @param nbtTag
     * @return
     */
    public <T> String toJsonStringForRawMessage(T nbtTag);
}
